package javabase.schoolwork.day6_11;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fance
 * @date 18-6-11 下午6:36
 */
public class BookStore {
    Map<IBook,Integer> bookIntegerMap = new HashMap<>();

    public BookStore(Map<IBook, Integer> bookIntegerMap) {
        this.bookIntegerMap = bookIntegerMap;
    }

    public void sale(IBook iBook)  {
        if (!bookIntegerMap.containsKey(iBook)) {
            return;
        }
        int remain = bookIntegerMap.get(iBook);
        if ( remain < 1) {
            return;
        }
        if (iBook.getPrice() > 40) {
            System.out.println("九折哟...");
            System.out.println("you need pay : " + iBook.getPrice() * 0.9);
        } else {
            System.out.println("八折哟...");
            System.out.println("you need pay : " + iBook.getPrice() * 0.8);

        }

        // remian --
        remain--;
        bookIntegerMap.put(iBook,remain);
    }
}
